﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Profari_Heldur_Utan_Um_Prof
{
    public partial class SessionPreview : Form
    {
        private static SqlConnection con = new SqlConnection("Data Source=HlynurX-PC\\SQLEXPRESS;Initial Catalog=lokaverkefni;Integrated Security=True ");
        private static DataTable dt = new DataTable();
        private static SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM sessio", con);
        private static DataSet ds = new DataSet();
        SqlDataReader r = null;

        public int globalSessionID;

        public SessionPreview(int id)
        {
            globalSessionID = id;
            InitializeComponent();
        }

        private void Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SessionPreview_Load(object sender, EventArgs e)
        {
            if (getWebPage() != null)
            {
                webBrowser1.Navigate(getWebPage());
            }

        }

        private string getWebPage()
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("Select url from sessio where id ="+globalSessionID,con);
                r = cmd.ExecuteReader();
                while (r.Read())
                {
                    return r.GetValue(0).ToString();
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine("Error: {0}", ex.ToString());
            }
            finally
            {
                if (con != null)
                    con.Close();
            }
            return null;
        }
        /*
        private string getWebPage()
        {
            conn = new MySql.Data.MySqlClient.MySqlConnection();
            cmd = new MySql.Data.MySqlClient.MySqlCommand();
            conn.ConnectionString = constr;

            string sqlSelected = "Select webPage from sessiontest where ID =" + sessionID + ";";

            try
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandText = sqlSelected;
                myData = cmd.ExecuteReader();
                if (myData.Read())
                {
                    return myData.GetValue(0).ToString();

                }


            }
            catch (MySqlException ex)
            {
                Console.WriteLine("Error: {0}", ex.ToString());

            }
            return null;
        }
        */
    }
}
